#include "../Unit--/unit--.h"
using namespace unit_minus;

#include <cstdio>
#include "../../wmi_constants.h"
#include "../../wmi_connectionmanager.h"
#include "../../wmi_registrymanager.h"

testSuite(WMIReaderSuite);

testCase(executeQueryTest_local, WMIReaderSuite)
{
    cout << "-------- Start WMI_Connection::executeQueryTest_local --------" << endl;

	WMI_ConnectionManager* wmiMng = new WMI_ConnectionManager();
	wmiMng->initCOMSecurityConfiguration();
	WMI_Connection wmiConnection;

	int expected = 0;	
	WMI_HResult* result = wmiMng->createConnection(PC_USER, PC_PASSWORD, PC_NAMESPACE, wmiConnection);
    delete result;

	result = wmiConnection.executeQuery(L"Select * from Win32_OperatingSystem");
	IEnumWbemClassObject* pEnumerator = NULL;
	
	pEnumerator = wmiConnection.getIEnumWbemClassObject();

	IWbemClassObject *pclsObj = NULL;
    ULONG uReturn = 0;
	
	int cont = 0;

	while (pEnumerator)
    {
        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
            &pclsObj, &uReturn);

        if(0 == uReturn)
        {
            break;
        }

		cont++;

        pclsObj->Release();
        pclsObj = NULL;
    }	

	assertTrue(!equalValueInfo(0, cont));
	wmiConnection.close();
    delete result;
    cout << "-------- End WMI_Connection::executeQueryTest_local Test --------" << endl;
    cout << endl;
    system("PAUSE");
}